package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 全局配置文件  添加六大注解 --随着框架启动而加载
 */
// 1. 添加注解  2. 实现接口
@Configuration
public class AppConfig implements WebMvcConfigurer {

    @Autowired
    private UserInterCeptor userInterCeptor;
    // 3. 重写方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterCeptor) // 添加拦截器
                .addPathPatterns("/**") // 拦截所有的请求
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")

                .excludePathPatterns("/reg.html"); // 设置不拦截的请求 ;
    }
}
